﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using com.crawler.common;
using com.crawler.db.Interface;

namespace com.crawler.components
{
    public class DBInstanceManager
    {

        #region 不同程序集反射

        private static object CreateObject(string path, string TypeName)
        {
            object obj = null;
            try
            {
                obj = Assembly.Load(path).CreateInstance(TypeName);

            }
            catch (System.Exception ex)
            {
                LogHelper.Error("反射获取对象失败" + ex.ToString());
            }

            return obj;
        }
        /// <summary>
        /// 创建网络访问接口实例
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static DataManager CreateDbObj(Consts.DBType i_db_type)
        {
            //从程序集创建对象实例
     
            string t_com_name = "com.crawler.db.MySQL.DataAccess" ;
            if (i_db_type == Consts.DBType.ServerSQL)
            {
                t_com_name = "com.crawler.db.SQL2000.DataAccess";
            }
            object objType = CreateObject("Crawler-4", t_com_name);
            return (DataManager)objType;
        }
        #endregion
    }
}
